<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Variable Validation and Policy Help</title>
    <style>
        body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; line-height: 1.6; }
        .back-link { margin-bottom: 20px; }
        .back-link a { text-decoration: none; color: #007acc; }
        .header { border-bottom: 2px solid #eee; padding-bottom: 20px; margin-bottom: 30px; }
        .section { margin-bottom: 30px; }
        h2 { color: #007acc; margin-top: 30px; }
        h3 { color: #333; margin-top: 25px; }
        code { background: #f1f3f4; padding: 2px 4px; border-radius: 3px; font-family: 'Monaco', monospace; font-size: 14px; }
        pre { background: #f8f9fa; padding: 15px; border-radius: 5px; overflow-x: auto; border-left: 4px solid #007acc; }
        .example { background: #f8f9fa; padding: 10px; border-radius: 3px; margin: 10px 0; }
        .policy-badge { display: inline-block; padding: 2px 6px; border-radius: 3px; font-size: 11px; margin-right: 5px; color: white; }
        .policy-immediate { background: #28a745; }
        .policy-lazy { background: #ffc107; color: #212529; }
        .policy-force { background: #dc3545; }
        .policy-skip { background: #6c757d; }
        .tip { background: #e3f2fd; padding: 15px; border-radius: 5px; border-left: 4px solid #2196f3; margin: 15px 0; }

        /* AsciiDoc admonition blocks (NOTE, TIP, WARNING, etc.) */
        .admonitionblock {
            margin: 1.5em 0;
            padding: 0.4em 0.6em;
            border-left: 4px solid;
            background: #f8f9fa;
            border-radius: 0 4px 4px 0;
        }

        .admonitionblock .title {
            font-weight: bold;
            text-transform: uppercase;
            font-size: 0.85em;
            margin-bottom: 0.25em;
            letter-spacing: 0.5px;
        }

        .admonitionblock .content {
            margin: 0;
        }

        /* Reduce spacing for paragraphs inside admonitions */
        .admonitionblock p {
            margin: 0.25em 0;
        }

        .admonitionblock p:first-child {
            margin-top: 0;
        }

        .admonitionblock p:last-child {
            margin-bottom: 0;
        }

        /* Specific admonition types */
        .admonitionblock.note {
            border-color: #17a2b8;
            background: #d1ecf1;
        }

        .admonitionblock.note .title {
            color: #0c5460;
        }

        .admonitionblock.tip {
            border-color: #28a745;
            background: #d4edda;
        }

        .admonitionblock.tip .title {
            color: #155724;
        }

        .admonitionblock.important {
            border-color: #ffc107;
            background: #fff3cd;
        }

        .admonitionblock.important .title {
            color: #856404;
        }

        .admonitionblock.warning,
        .admonitionblock.caution {
            border-color: #dc3545;
            background: #f8d7da;
        }

        .admonitionblock.warning .title,
        .admonitionblock.caution .title {
            color: #721c24;
        }
    </style>
</head>
<body>
    <div class="back-link">
        <a href="index.html">← Back to Layer Index</a>
    </div>

    <div class="header">
        <h1>Variable Validation and Policy Help</h1>
        <p>Reference for rpi-image-gen layer variable validation rules and set policies.</p>
    </div>

    <div class="section">
        <h2 id="set-policies">Set Policies</h2>
        <p>Set policies determine when and how environment variables are applied during the build process:</p>

        {%- for policy in validation.set_policies %}
        <h3><span class="policy-badge policy-{{ policy.class }}">{{ policy.name }}</span> {{ policy.name.title() }}{% if policy.name == 'immediate' %} (Default){%- endif %}</h3>
        <p>{{ policy.description }}</p>
        {%- endfor %}

        <div class="tip">
            <strong>Policy Aliases:</strong><br>
            <code>true/yes/1/y</code> → immediate<br>
            <code>false/no/0/n</code> → skip
        </div>
    </div>

    <div class="section">
        <h2>Validation Types</h2>

        {%- if validation.basic_types %}
        <h3>Basic Types</h3>
        {%- for type in validation.basic_types %}
        <div class="example">
            <strong>{{ type.description }}</strong>
        </div>
        {%- endfor %}
        {%- endif %}

        {%- for type in validation.advanced_types %}
        <h3>{{ type.title.split(' - ')[0] if ' - ' in type.title else type.name.title() + ' Types' }}</h3>
        <div class="example">
            <strong>{{ type.title }}</strong>
            {%- if type.details %}
            {%- for detail in type.details %}
            {%- if detail.strip() %}
            <br>{{ detail }}
            {%- endif %}
            {%- endfor %}
            {%- endif %}
        </div>
        {%- endfor %}
    </div>

    <div class="section">
        <h2>Placeholders</h2>
        <p>Auto-substituted in variable values:</p>
        <div class="example">
            {%- for placeholder in validation.placeholders %}
            <strong><code>{{ placeholder.name }}</code></strong> - {{ placeholder.description }}<br>
            {%- endfor %}
            <em>Escape with <code>\${NAME}</code> to keep the literal text.</em>
        </div>
    </div>

    <div class="section">
        <h2>Example Variable Definitions</h2>
        <pre><code># Port number validation
X-Env-Var-port-Valid: int:1024-65535

# Environment selection
X-Env-Var-env-Valid: development,staging,production

# Hostname validation
X-Env-Var-hostname-Valid: regex:^[a-zA-Z0-9.-]+$

# Boolean flag
X-Env-Var-debug-Valid: bool

# Component selection with keywords
X-Env-Var-component-Valid: keywords:frontend,backend,database</code></pre>
    </div>

    <div class="tip">
        <strong>Testing Tip:</strong> Use <code>rpi-image-gen metadata --lint &lt;file&gt;</code> to quickly check syntax and field names without validating environment variables.
    </div>
</body>
</html>
